define(function(require, exports){
  'use strict';
  var $ = require('seajs/jquery.min');
  var _const = require('seajs/fn/fnConst');
  var fnUtils = require('seajs/fn/fnUtils');
  var Task = require('seajs/fn/fnTask');

  /***************************************
  **********  MSG 数据组装 Start *********
  ****************************************/
  var getAccessRtpMsg = function(cid, sid, uid, destip, destport, payloadtype, sendflag){
   if(_const.debug){
     console.log('=========== sendRTPMsg() ==========');
     console.log('sid', sid, 'cid', cid, 'uid', uid, 'destip',
      destip, 'destport', destport, 'payloadtype', payloadtype, 'sendflag', sendflag);
   }
   if(sid && cid){
     return {
       cmd: _const.RTP_WS.EVENT_TYPE.ACCESS.REQ,
       sid: sid,
       cid: cid,
       uid: uid,
       destip: destip,
       destport: destport,
       payloadtype: payloadtype,
       sendflag: sendflag
     }
   }
  }

  var getSendRtpMsg = function(sid, cid, sendflag){
    if(sid && cid){
      return {
        cmd: _const.RTP_WS.EVENT_TYPE.START_SEND.REQ,
        sid: sid,
        cid: cid,
        sendflag: sendflag
      }
    }
  }

  var getStopRtpMsg = function(sid, cid){
    if(sid && cid){
      return {
        cmd:  _const.RTP_WS.EVENT_TYPE.STOP_SEND.REQ,
        sid: sid,
        cid: cid
      }
    }
  }

  var getOtherMsg = function(){
    if(_const.debug){
    console.log('=========== getOtherMsg() ==========');
    }
  }
 
  /***************************************
  **********  MSG 数据组装 end ***********
  ****************************************/
  var accessRtpHandler = function(container, msg){
    if(_const.debug){
      console.log('=========== accessRtpHandler() ==========');
    }
  }

  var stopRtpHandler = function(container, msg){
  }

  //{
  //  “cmd”:8003,
  //  “sid”:123,
  //  “cid”:12345,
  //  “rsp”:1//0-错误 1-ok
  // }
  var sendRtpHandler = function(container, msg){
    var audio = document.getElementById('ptt_music');
    if(audio && audio.paused){
      if(msg.sendflag === 0){
        audio.src = 'media/ptt_up_0921.ogg';
      }else{
        if(msg.rsp === 1){
          audio.src = 'media/ptt_down_0921.ogg';
        }else{
          audio.src = 'media/ptt_down_fail_0921.ogg';
        }
      }  
      audio.play();
    }
  
  }

  var recvPttHandler = function(container, msg){
    var uid = msg.uid;
    console.log(msg);
    container.recvPtt = msg.recvPtt;
    
    var audio = document.getElementById('ptt_music');
    
    // audio.pause();
    if(container.recvPtt === 1){
      $('#curr_status').removeClass('ptt-status-free')
            .removeClass('ptt-status-speeking')
            .addClass('ptt-status-forbidden');
      //$('#ptt_status_span').html(container.slidebar.memberMap.get(uid).memberName + '正在发言');
      $('#ptt-status-p').html(container.slidebar.memberMap.get(uid).memberName + '正在发言');
      $('#ptt-button').attr('src','images/talk_leisure_down.png');
      $('#ptt-status-i').html('发言中');
      $('.status-content .content-right i.icon').css('background','url(images/talking_reminder.png) no-repeat');
      audio.src = "media/ptt_down_0921.ogg";
    }else{
      $('i[id*=commenting_group_').css('display', 'none');
      $('#curr_status').removeClass('ptt-status-speeking')
            .removeClass('ptt-status-forbidden')
            .addClass('ptt-status-free');
      $('#ptt_status_span').html('空闲');
      $('#ptt-status-i').html('空闲');
      $('.status-content .content-right i.icon').css('background','url(images/talk_reminder.png) no-repeat');
      $('#ptt-status-p').html('');
      $('#ptt_status_span').html('空闲');
      $('#ptt-button').attr('src','images/talk_leisure.png');
      audio.src = "media/ptt_up_0921.ogg";
    }
    audio.play();
  }

  var otherHandler = function(container, msg){
    if(_const.debug){
      console.log('=========== otherHandler() ==========');
    }
  }

  exports.getAccessRtpMsg = getAccessRtpMsg,
  exports.getSendRtpMsg = getSendRtpMsg,
  exports.getStopRtpMsg = getStopRtpMsg,
  exports.getOtherMsg = getOtherMsg,

  // ====== handler
  exports.accessRtpHandler = accessRtpHandler,
  exports.stopRtpHandler = stopRtpHandler,
  exports.sendRtpHandler = sendRtpHandler,
  exports.recvPttHandler = recvPttHandler,
  exports.otherHandler = otherHandler;
});